package com.example.ioc;

import com.example.ioc.component.UserComponent;
import com.example.ioc.controller.UserController;
import com.example.ioc.model.UserInfo;
import com.example.ioc.resp.UserRepository;
import com.example.ioc.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {


		//以前老方法
		//UserController userController=new UserController();
		//userController.sayhi();

		ApplicationContext context=SpringApplication.run(DemoApplication.class,args);
//		//根据类型来获取对象
//		UserController bean = context.getBean(UserController.class);
//		bean.sayhi();
//
//		//根据名称来获取对象
//		UserController userController =(UserController) context.getBean("userController");
//		userController.sayhi();
//
//
//		//有名称有类型
//		UserController userController1 = context.getBean("userController", UserController.class);
//		userController1.sayhi();
//
//		//单例模式
//		System.out.println(bean);
//		System.out.println(userController);
//		System.out.println(userController1);
//
//
//
//		UserService bean = context.getBean(UserService.class);
//		bean.sayhi();
		UserComponent bean1 = context.getBean(UserComponent.class);
		bean1.sayhi();
//		UserRepository bean2 = context.getBean(UserRepository.class);
//		bean2.sayhi();
//
		//UserInfo bean = context.getBean(UserInfo.class);
		//System.out.println(bean);
		//Object userInfo = context.getBean("zhangsan");
		//System.out.println(userInfo);
/*
		UserController bean = context.getBean(UserController.class);
		bean.sayhi();*/


	}

}
